﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AMebooking._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">
    <meta charset="UTF-8" />
    <title>Automaster Planning Tool</title>
    <link rel="stylesheet" href="Assets/css/bootstrap.css" type="text/css" media="screen" title="no title" charset="utf-8" />
    <link rel="stylesheet" href="Assets/css/custom.css" type="text/css" media="screen" title="no title" charset="utf-8" />
    <link rel="stylesheet" href="Assets/js/dojo/dijit/themes/claro/Dialog.css" type="text/css" media="screen" title="no title" charset="utf-8" />

    <script type="text/javascript">
        dojoConfig = {
            isDebug: true,
            packages: [{
                name: "apt",
                location: "../../apt"
            }]
        };
        var storedata = {};
    </script>

    <script type="text/javascript" src="Assets/js/date.js"></script>
    <script type="text/javascript" src="Assets/js/dojo/dojo/dojo.js"></script>

    <script type="text/javascript" charset="utf-8">
        Date.prototype.getMonthName = function() {
            var m = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
                'August', 'September', 'October', 'November', 'December'
            ];
            return m[this.getMonth()];
        };
        Date.prototype.getDayName = function() {
            var d = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
                'Thursday', 'Friday', 'Saturday'
            ];
            return d[this.getDay()];
        };
        Date.prototype.getWeek = function() {
            var onejan = new Date(this.getFullYear(), 0, 1);
            return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
        };
        String.prototype.toDateFromAspNet = function() {
            // TODO: This does not account for timezones.
            var dateStr = this.replace(/[\/Date\(\)]/g, '').replace(/(\+.*)/g, '');
            var date = new Date(parseInt(dateStr));
            // date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
            return date;
        };
        String.prototype.toDateFromAspNetFormated = function() {
            var d = this.toDateFromAspNet();
            var month;
            var day;
            if (d.getMonth() + 1 < 10) {
                month = '0' + (d.getMonth() + 1);
            } else {
                month = d.getMonth() + 1;
            }
            if (d.getDate() < 10) {
                day = '0' + d.getDate();
            } else {
                day = d.getDate();
            }
            return d.getFullYear() + "-" + month + "-" + day;
        };

        String.prototype.parseISO8601 = function() {
            var parts, dateParts, timeParts, timeSubParts, timeSecParts, timeHours, divider;

            divider = (this.indexOf('T') != -1) ? 'T' : ' ';

            parts = this.split(divider);
            dateParts = parts[0].split('-');

            if (dateParts.length < 2) return null;

            if (parts[1].indexOf('Z') != -1) {
                timeParts = parts[1].split('Z');
            } else if (parts[1].indexOf('+') != -1) {
                timeParts = parts[1].split('+');
            } else if (parts[1].indexOf('-') != -1) {
                timeParts = parts[1].split('-');
            } else {
                timeParts = [parts[1]];
            }

            timeSubParts = timeParts[0].split(':');

            timeHours = Number(timeSubParts[0]);

            var _date = new Date;
            _date.setFullYear(Number(dateParts[0]));
            _date.setMonth(Number(dateParts[1]) - 1);
            _date.setDate(Number(dateParts[2]));
            _date.setHours(Number(timeHours));
            _date.setMinutes(Number(timeSubParts[1]));

            if (timeSubParts[2]) {
                timeSecParts = timeSubParts[2].split(".");
                _date.setSeconds(Number(timeSecParts[0]));
            }
            if (timeSecParts[1]) _date.setMilliseconds(Number(timeSecParts[1]));
            if (timeSubParts[3]) _date.setMilliseconds(Number(timeSubParts[3]));
            // by using setUTC methods the date has already been converted to local time(?)
            return _date;
        };
    </script>

</head>

<body>
    <div class="wrap">
        <div id="ptloading" class="alert alert-info" style="position: absolute; left: 20px;
        right: 20px; top: 20px; bottom: 20px;">
            <table style="height: 100%;" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td style="text-align: center; vertical-align: middle;">
                        <h1>The time booking transaction </h1>
                        <br />
                        <img src="Assets/img/spinner.gif" alt="" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="pt">
            &nbsp;
        </div>
    </div>

    <script type="text/javascript" charset="utf-8">
        dojo.ready(function() {
            dojo.require('apt.PlanningTool');
            dojo.require("dojo.store.JsonRest");
            var resx = new dojo.store.JsonRest({
                target: "Service/Resources.aspx"
            });
            resx.query({
                type: 'initd',
                idProperty: 'initd'
            }).then(function(results) {
                storedata = storedata || {};
                storedata.departments = results.departments;
                storedata.resources = results.resources;
                storedata.shifts = results.shifts;
                setTimeout(function() {
                    window.pt = new apt.PlanningTool({
                        elementHeight: 44
                    }, 'pt');
                }, 10); //options,elementID))
            });
        });
    </script>

</body>

</html>